package com.ouc.yyi.user.springcloud.user.config;

import com.ouc.yyi.user.springcloud.user.userInfo.bo.UserBo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Map;

/**
 * @description:
 * @author: yyi
 * @date: 2022/8/26 14:40
 * @version: 1.0
 **/

public class Test {
    public static void main(String[] args) {
        // 创建和初始化容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
        // ① 我们直接从容器中拿出 map 对象
        System.out.println(context.getBean("userBo", UserBo.class));
        MyConfiguration configuration = context.getBean("myConfiguration", MyConfiguration.class);
        // ② 通过调用 MyConfiguration 对象中的 getMap 获取 Map 对象
        System.out.println(configuration.userBo());

        AnnotationConfigApplicationContext contextCom = new AnnotationConfigApplicationContext(MyComponent.class);
        // ① 我们直接从容器中拿出 hello 对象
        System.out.println(contextCom.getBean("userBo", UserBo.class));
        MyComponent myComponent = contextCom.getBean("myComponent", MyComponent.class);
        // ② 通过调用 component 对象中的 hello() 获取 hello 对象
        System.out.println(myComponent.userBo());
    }
}
